//
//  ChuJJiLuV.m
//  BrushFace
//
//  Created by timer_q on 16/1/17.
//  Copyright © 2016年 Zzz. All rights reserved.
//

#import "ChuJJiLuV.h"
#import "ChuJieHeaderV.h"
#import "ChuJieCell.h"

@implementation ChuJJiLuV
{
    UITableView *_tableView;
    CGFloat viewHeight;
    ChuJieHeaderV *chujieHeader;
    NSMutableArray *_dataArray;
    UITableView *_baseTable;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        viewHeight = frame.size.height;
        _dataArray = [[NSMutableArray alloc] init];
        [self UIConfig];
    }
    return self;
}
- (void)UIConfig{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, viewHeight) style:UITableViewStylePlain];
    chujieHeader = [ChuJieHeaderV loadBundleNib];
    chujieHeader.frame = CGRectMake(0, 0, SCREEN_WIDTH, 60);
    _tableView.tableHeaderView = chujieHeader;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = UIColorFromRGB(ColorValueForBackView_Gray);
    _tableView.showsHorizontalScrollIndicator = NO;
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self addSubview:_tableView];

}
#pragma mark - tableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ChuJieCell *cell = [ChuJieCell loadBundleNib];
    NSDictionary * subDict = [_dataArray objectAtIndex:indexPath.row];
    ;
    cell.cellImageVIew.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",(arc4random()%42)+1]];
   #pragma mark------qiweipeng
    
    //case 0:{cell.guanxiLabel.text = @"朋友";把case＝0的状态改成朋友
    
    switch ([[subDict objectForKey:@"level"] integerValue]) {
        case 0:{cell.guanxiLabel.text = @"朋友";}break;
        case 1:{cell.guanxiLabel.text = @"朋友";}break;
        case 2:{cell.guanxiLabel.text = @"朋友的朋友";}break;
        default:break;}
    
#pragma mark-----------------------
    cell.talkLabel.text = [NSString stringWithFormat:@"%@",[subDict objectForKey:@"content"]];
    cell.timeLabel.text = [NSString stringWithFormat:@"%@",[subDict objectForKey:@"createtime"]];
    cell.moneyLabel.text = [NSString stringWithFormat:@"+%.2f",[[NSString stringWithFormat:@"%@",[subDict objectForKey:@"amount"]] floatValue]];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 55;
}
- (void)setChujieDataWith:(id)data{
    chujieHeader.friendLabel.text = [NSString stringWithFormat:@" 朋友+%@    ",[data objectForKey:@"level1"]];
    chujieHeader.friendsLabel.text = [NSString stringWithFormat:@" 朋友的朋友+%@    ",[data objectForKey:@"level2"]];
    [_dataArray removeAllObjects];
    [_dataArray addObjectsFromArray:[data objectForKey:@"data"]];
    [_tableView reloadData];
    chujieHeader.zongLabel.text = [NSString stringWithFormat:@"已有%ld位好友出借",_dataArray.count];
    
}
- (void)baseTableView:(UITableView *)baseTable{
    _baseTable = baseTable;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (_tableView.contentOffset.y<0) {
        _baseTable.contentOffset = _tableView.contentOffset;
    }
}
@end
